package workers

import (
	"gitee.com/captials-team/ubdframe/src/domain/dto/cmddata"
	v1log "gitee.com/captials-team/ubdframe/src/pkg/logs"
	"gitee.com/captials-team/ubdframe/src/pkg/wsserver"
	"go.uber.org/dig"
)

type LogWorker struct {
	l v1log.ILog
}

func (w *LogWorker) Name() string {
	return "log"
}

func (w *LogWorker) Receive(cmd *cmddata.ClientCmd) {
	w.l.Info("RECEIVE %+v", cmd)

	cmd.Client.SendMessage(&cmddata.ClientAnswer{
		Group:   w.Name(),
		Message: "receive success",
	})
}

func (w *LogWorker) Online(client *wsserver.Client) {
	w.l.Info("ONLINE %s", client.ID())
	client.SendMessage(&cmddata.ClientAnswer{
		Group:   w.Name(),
		Message: "welcome",
	})
}

func (w *LogWorker) Close(client *wsserver.Client) {
	w.l.Info("CLOSED %s", client.ID())
}

func (w *LogWorker) NeedAccredit(client *wsserver.Client) bool {
	return false
}

func NewLogWorker(di *dig.Container, logger v1log.ILog) *LogWorker {
	return &LogWorker{
		l: logger,
	}
}
